package cn.well.cloud.quartz.modular.controller;

import cn.hutool.core.date.DateUtil;
import cn.stylefeng.roses.core.util.SpringContextHolder;
import cn.well.cloud.quartz.modular.service.impl.TimetaskLogServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * 定时任务
 *
 * 定时任务日志处理业务
 * wison
 * 下午9:24:30
 */
@Component
@DependsOn("springContextHolder")
public class TimeTaskLogJobController {
    private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());

    private TimetaskLogServiceImpl timetaskLogService = SpringContextHolder.getBean("timetaskLogServiceImpl");
    
    /**
     * 清理timeTaskLog表数据任务
     * 2020年2月28日
     * @param data
     */
    public void deleteTimeTaskLog(String data) {
        LOGGER.debug("【定时清除timeTaskLog 7天之前的记录】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>开始执行"); 
        Date currentDate = new Date();
        int day = -7;
        Date deleteDate = DateUtil.offsetDay(currentDate, day);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.le("create_time", deleteDate); 
        boolean ret = timetaskLogService.remove(queryWrapper);
        try{
            Thread.currentThread().sleep(70000);
         }catch(InterruptedException ie){
         ie.printStackTrace();
        }
        if(ret){
            LOGGER.debug("【定时清除timeTaskLog 7天之前的记录】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>执行成功");
        }else{
            LOGGER.debug("【定时清除timeTaskLog 7天之前的记录】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>执行失败");
        }
      }
}

